package sktit.practice.jpaint.draw;

import java.util.ArrayList;

import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import sktit.practice.jpaint.canvas.CanvasManager;

public class AbstractDraw implements Draw {

	protected boolean isDrawing = false;
	protected Point begin = new Point(0, 0);
	protected Point temp = new Point(0, 0);
	protected ArrayList<Point> vertex = new ArrayList<Point>();
	
	protected Shell shell;
	protected Display display;
	protected Color colorBorder;
	protected int width;
	private int style;
	
	protected CanvasManager canvasManager = new CanvasManager();

	protected PaintListener paintListener = new PaintListener(){

		@Override
		public void paintControl(PaintEvent arg0) {
			canvasManager.draw();
		}
		
	};
	protected MouseListener mouseListener;
	protected MouseMoveListener mouseMoveListener;
	
	public AbstractDraw(Shell aShell, Display aDisplay, Color aColor, int aWidth,
			int aStyle)
	{
		shell = aShell;
		display = aDisplay;
		setStyle(aStyle);
		setColorBorder(aColor);
		setWidth(aWidth);
		shell.addPaintListener(paintListener);
	}
	
	@Override
	public MouseListener getMouseListener() {
		return mouseListener;
	}

	@Override
	public MouseMoveListener getMouseMoveListener() {

		return mouseMoveListener;
	}
	
	@Override
	public PaintListener getPaintListener() {
		return paintListener;
	}
	
	public void setColorBorder(Color colorBorder) {
		this.colorBorder = colorBorder;
	}
	
	public Color getColorBorder() {
		return colorBorder;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getWidth() {
		return width;
	}

	public void setStyle(int style) {
		this.style = style;
	}

	public int getStyle() {
		return style;
	}
	
	protected GC createGC()
	{
		GC gc = new GC(shell);
		gc.setForeground(colorBorder);
		gc.setLineWidth(width);
		gc.setLineStyle(style);
		return gc;
	}
	
	public void clear()
	{
		canvasManager.clear();
	}
	
	public CanvasManager getCanvasManager()
	{
		return canvasManager;
	}
	
	public void setCanvasManager(CanvasManager aCanvas)
	{
		canvasManager = aCanvas;
	}
	
	
}
